<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>图书管理</title>
    <%@include file="/pages/comm/head.jsp" %>
    <script type="text/javascript">
        $(function () {
            $("a.deleteClass").click(function () {
                return confirm("你确定删除" + $(this).parent().parent().find("td:eq(1)").text() + "?")
            })
        })
    </script>
</head>
<body>

<div id="header">
    <img class="logo_img" alt="" src="static/img/logo.gif">
    <span class="wel_word">图书管理系统</span>
    <%@include file="/pages/comm/manager_menu.jsp" %>

</div>

<div id="main">
    <table>
        <tr>
            <td>ID</td>
            <td>名称</td>
            <td>价格</td>
            <td>作者</td>
            <td>销量</td>
            <td>库存</td>
            <td colspan="2">操作</td>
            <c:forEach items="${requestScope.page.items}" var="book">
        </tr>
        <td>${book.id}</td>
        <td>${book.name}</td>
        <td>${book.price}</td>
        <td>${book.author}</td>
        <td>${book.sales}</td>
        <td>${book.stock}</td>
        <td><a href="manager/bookServlet?action=getBook&id=${book.id}&method=upDate&pageNo=${requestScope.page.pageTocal}">修改</a></td>
        <td><a class="deleteClass" href="manager/bookServlet?action=deleteBookId&id=${book.id}&pageNo=${requestScope.page.pageTocal}">删除</a></td>
        </tr>
        </c:forEach>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td><a href="pages/manager/book_edit.jsp?method=add&pageNo=${requestScope.page.pageTocal}">添加图书</a></td>
        </tr>
    </table>
    <div id="page_nav">
        <c:if test="${requestScope.page.pageNo>1}">

            <a href="manager/bookServlet?action=page&pageNo=1">首页</a>
            <a href="manager/bookServlet?action=page&pageNo=${requestScope.page.pageNo-1}">上一页</a>
        </c:if>
        <%--			<a href="manager/bookServlet?action=page&pageNo=${requestScope.page.pageNo-1}">${requestScope.page.pageNo-1}</a>--%>
        <%--			<a href="manager/bookServlet?action=page&pageNo=${requestScope.page.pageNo+1}">${requestScope.page.pageNo+1}</a>--%>

        <%--        页码输出前--%>
<%--页码总数小于五--%>
        <c:choose>
           <c:when test="${requestScope.page.pageTocal<=5}">
               <c:forEach begin="1" end="${requestScope.page.pageTocal}" var="i">
                  <c:if test="${requestScope.page.pageNo!=i}">
                   <a href="manager/bookServlet?action=page&pageNo=${i}">[${i}]</a>
                  </c:if>
                   <c:if test="${requestScope.page.pageNo==i}">
                      ${i}
                   </c:if>
               </c:forEach>
           </c:when>
<%--            总的页码大于5--%>
            <c:when test="">

            </c:when>
        </c:choose>
        <%--        页码输出后--%>
        <c:if test="${requestScope.page.pageNo<requestScope.page.pageTocal}">
            <a href="manager/bookServlet?action=page&pageNo=${requestScope.page.pageNo+1}">下一页</a>
            <a href="manager/bookServlet?action=page&pageNo=${requestScope.page.pageTocal}">末页</a>
        </c:if>
        共${requestScope.page.pageTocal}页，${requestScope.page.pageTocalCount}条记录
        到第<input value="${page.pageNo}" name="pn" id="pn_input"/>页
        <input id="searchPage" type="button" value="确定">
        <script type="text/javascript">
            $(function () {
                $("#searchPage").click(function () {
                    <%--var pageToTal=	${requestScope.page.pageTocal};--%>
                    var pageNo = $("#pn_input").val();

                    <%--	if (pageNo<1||pageNo>pageToTal){--%>
                    <%--	 pageNo= 1;--%>
                    <%--}--%>
                    <%--	if (pageNo>pageToTal){--%>
                    <%--		pageNo=pageToTal--%>
                    <%--	}--%>
                    location.href = "${pageScope.basePath}manager/bookServlet?action=page&pageNo=" + pageNo;
                })
            })
        </script>
    </div>
</div>

<%@include file="/pages/comm/foot.jsp" %>
>

</body>
</html>